package com.zq.thread.Observe;

import java.util.concurrent.TimeUnit;

/**
 * @Author: zhaoqi
 * @Date: 2020/5/24 1:00
 * @Version 1.0
 */

public class TestObservable {

    public static void main(String[] args) {


        //  为什么回调没有成功，没有拿到返回值   todo
        final TaskLifececle<String> lifececle = new TaskLifececle.EmptyLifecycle<String>(){

            public void onFinish(Thread thread, String result) {
                if (null == result || "".equals(result)){
                    System.out.println(12456456);
                }
                System.out.println("The result is " + result);
            }

        };


        Observable observableThread = new ObservableThread<>(lifececle,() -> {
           try {
               TimeUnit.SECONDS.sleep(3);
           } catch (InterruptedException e){
              e.printStackTrace();
           }
            System.out.println("finashed done.");
            return "Hello Observeable";
        });
        observableThread.start();

        //Callable
        //test();
    }

    private static void test() {
        Observable observable = new ObservableThread<>(()-> {
            try {
                TimeUnit.SECONDS.sleep(10);
            } catch (InterruptedException e){
                e.printStackTrace();
            }
            System.out.println("finashed done.");
            return null;
        });
        observable.start();
    }

}
